﻿<UserControl x:Class="ModernAudioTagger.Content.ContentFileList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:blogic="clr-namespace:ModernAudioTagger.BusinessLogic"
             xmlns:provider="clr-namespace:ModernAudioTagger.Provider"
             xmlns:converter="clr-namespace:ModernAudioTagger.Converter"
             xmlns:helper="clr-namespace:ModernAudioTagger.Helpers"
             xmlns:view="clr-namespace:ModernAudioTagger.View"
             xmlns:mscorelib="clr-namespace:System;assembly=mscorlib"             
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"                
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"                   
             xmlns:explorer="clr-namespace:WpfExplorerTree;assembly=WpfExplorerTree"
             AllowDrop="True"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.DataContext>
        <Binding Source="{x:Static provider:ViewModelLocator.Instance}" Path="LocalSystemVM" />
    </UserControl.DataContext>

    <UserControl.Resources>
        <!--<blogic:DataContextSpy x:Key="spyMusicDbVM" DataContext="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=MusicDbVM }"></blogic:DataContextSpy>-->
        <!--<blogic:DataContextSpy x:Key="spyTrackTagVM" DataContext="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=TrackTagVM }"></blogic:DataContextSpy>-->
        <converter:DataGridRowIndexConverter x:Key="indexConverter" />
        <converter:FilenameConverter x:Key="filenameConverter" />
        <converter:NullToVisibilityConverter x:Key="nullToVisibilityConverter" />
        <!--<converter:ListItemCollectionConverter x:Key="listItemCollectionConverter" />-->
        <converter:IsEqualOrGreaterThanConverter x:Key="isEqualOrGreaterThanConverter" />
    </UserControl.Resources>


    <DockPanel>

        <StackPanel DockPanel.Dock="Top">
            <TextBlock FontSize="{StaticResource SmallFontSize}" Text="Path" Style="{StaticResource Title}" HorizontalAlignment="Center" Margin="{StaticResource DefaultTopMargin}" />

            <TextBlock             
                Visibility="{Binding SelectedPath, Converter={StaticResource nullToVisibilityConverter}, ConverterParameter=False}"
                Height="Auto" 
                Width="Auto"             
                FontSize="{StaticResource SmallFontSize}" 
                HorizontalAlignment="Center" 
                Margin="{StaticResource DefaultTopMargin}">     
                <Hyperlink Command="{x:Static view:ViewCommands.OpenFolderLocation}" CommandParameter="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=LocalSystemVM.SelectedPath}" >
                    <TextBlock Text="{Binding SelectedPath}"></TextBlock>
                </Hyperlink>
            </TextBlock>
            <TextBlock Height="Auto" FontSize="{StaticResource SmallFontSize}" HorizontalAlignment="Center" Width="Auto" Margin="{StaticResource DefaultTopMargin}"  Visibility="{Binding SelectedPath, Converter={StaticResource nullToVisibilityConverter}}">
                <Hyperlink Command="{Binding OpenFolderDialogCommand}">Click here</Hyperlink>
            </TextBlock>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="{StaticResource DefaultTopMargin}">
                <TextBlock VerticalAlignment="Center" FontSize="{StaticResource SmallFontSize}" Text="Filter" Style="{StaticResource Title}"  />
                <ComboBox IsEditable="True" Text="{Binding SelectedExtension, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Filters, Mode=OneTime}" FontSize="{StaticResource SmallFontSize}" HorizontalAlignment="Center" Margin="{StaticResource DefaultLeftMargin}" Width="200">
                    <ComboBox.InputBindings>
                        <KeyBinding Key="Enter" Command="{Binding RefreshFilelistCommand}" />
                    </ComboBox.InputBindings>
                </ComboBox>
            </StackPanel>

        </StackPanel>

        <ListView                            
            BorderThickness="1"
            BorderBrush="{DynamicResource SeparatorBackground}"
            Margin="{StaticResource DefaultTopLeftMargin}"
            ItemsSource="{Binding Files}" 
            SelectionMode="Extended"                 
            helper:ListBoxMultipleSelectorHelper.SelectedItems="{Binding SelectedFiles, Mode=TwoWay}"            
        >
            <ListView.Style>
                <Style TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListView}}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=LocalSystemVM.Files.Count, Converter={StaticResource isEqualOrGreaterThanConverter}, ConverterParameter='1'}" Value="True">
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListView.Style>
            <ListView.Resources>
                <ContextMenu x:Key="ItemContextMenu">
                    <MenuItem Header="Open folder location" CommandParameter="{Binding FileName}" Command="{Binding Source={x:Static view:ViewCommands.OpenFolderLocation}}">
                        <MenuItem.Icon>
                            <Path Fill="#FF2B2B2B"
                                      Width="14.3775"
                                      Height="14"
                                      Canvas.Left="0.311264"
                                      Canvas.Top="0.500005"
                                      Stretch="Uniform"
                                      Data="{StaticResource openFolderPathData}"
                                      />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Play file" CommandParameter="{Binding FileName}" Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=MainVM.PlayFileCommand}">
                        <MenuItem.Icon>
                            <Path Fill="#FF2B2B2B"
                                      Width="14.3775"
                                      Height="14"
                                      Canvas.Left="0.311264"
                                      Canvas.Top="0.500005"
                                      Stretch="Uniform"
                                      Data="{StaticResource playPathData}"
                                      />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Tag selected files" CommandParameter="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=LocalSystemVM.SelectedFiles}" Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=LocalSystemVM.TagSelectedFilesCommand}">
                        <MenuItem.Icon>
                            <Path Fill="#FF2B2B2B"
                                      Width="14.3775"
                                      Height="14"
                                      Canvas.Left="0.311264"
                                      Canvas.Top="0.500005"
                                      Stretch="Uniform"
                                      Data="{StaticResource tagPathData}"
                                      />
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </ListView.Resources>
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
                    <Setter Property="ContextMenu" Value="{StaticResource ItemContextMenu}" />
                </Style>
            </ListView.ItemContainerStyle>
            <i:Interaction.Behaviors>
                <helper:ListBoxItemRefreshBehavior />
            </i:Interaction.Behaviors>
            <ListView.View>
                <GridView>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <mui:ModernButton EllipseDiameter="16" IconWidth="8" IconHeight="8" IconData="{StaticResource playPathData}" CommandParameter="{Binding FileName}" Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=MainVM.PlayFileCommand}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding FileName, Converter={StaticResource filenameConverter}}" Width="250" />                    
                </GridView>
            </ListView.View>

            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction CommandParameter="{Binding SelectedFiles}" Command="{Binding ShowFileTagCommand}"  />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </ListView>

    </DockPanel>

    <!--<i:Interaction.Triggers>
        <i:EventTrigger EventName="OnMediaPlayEvent" SourceObject="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=MainVM}">            
            <ei:ChangePropertyAction TargetName="path_mediastatus" PropertyName="Data" Value="{StaticResource stopPathData}" />            
        </i:EventTrigger>
        <i:EventTrigger EventName="OnMediaStopEvent" SourceObject="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=MainVM}">
            <ei:ChangePropertyAction TargetName="path_mediastatus" PropertyName="Data" Value="{StaticResource playPathData}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>-->

</UserControl>
